package com.sp.common.vo;

import com.sp.common.enu.CodeEnum;
import com.sp.common.enu.ReturnCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Schema(name= "通用返回类")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private T data;

       @Schema(name= "200->成功 | 1->失败")
    private String code;


       @Schema(name="提示的消息")
    private String msg;

    public static <T> Result<T> error() {
        Result<T> resultVO = new Result<>();
        resultVO.setCode(CodeEnum.ERROR.getCode());
        resultVO.setMsg(CodeEnum.ERROR.getMsg());
        return resultVO;
    }

    public static <T> Result<T> succeed(String msg) {
        return succeedWith(null, CodeEnum.SUCCESS.getCode(), msg);
    }
    public static <T> Result<T> error(String msg) {
        return succeedWith(null, CodeEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        return succeedWith(model, CodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> error(T model, String msg) {
        return succeedWith(model, CodeEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> succeed(T model) {
        return succeedWith(model, CodeEnum.SUCCESS.getCode(), "");
    }

    public static <T> Result<T> error(T model) {
        return succeedWith(model, CodeEnum.ERROR.getCode(), "");
    }

    public static <T> Result<T> succeedWith(T datas, String code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> failed(String msg) {
        return failedWith(null, CodeEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> other(String msg) {
        return failedWith(null, CodeEnum.OTHER.getCode(), msg);
    }

    public static <T> Result<T> other(T model,String msg) {
        return failedWith(model, CodeEnum.OTHER.getCode(), msg);
    }

    public static <T> Result<T> failed(T model, String msg) {
        return failedWith(model, CodeEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> failedWith(T datas, String code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> result(ReturnCodeEnum returnCodeEnum) {
        return new Result<>(null, returnCodeEnum.getRetCode(), returnCodeEnum.getRetDesc());
    }

    public static <T> Result<T> resultDate(T date, ReturnCodeEnum returnCodeEnum) {
        return new Result<>(date, returnCodeEnum.getRetCode(), returnCodeEnum.getRetDesc());
    }

    public static <T> Result<T> resultData(T data, String msg) {
        return new Result<>(data, CodeEnum.ERROR.getCode(),msg );
    }
}
